package com.ms.p2p.template.method;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ms.p2p.entity.loan.LoanCategory;
import com.ms.p2p.provider.LoanCategoryProvider;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by xing_ on 2017/6/10.
 */
@Repository
public class BorrowTypeMethod implements TemplateMethodModelEx {

    @Reference
    private LoanCategoryProvider loanCategoryProvider;


    @Override
    public Object exec(List arguments) throws TemplateModelException {
        if (arguments != null && !arguments.isEmpty() && arguments.get(0) != null &&
                StringUtils.isNotEmpty(arguments.get(0).toString())) {
            String id = arguments.get(0).toString();
            LoanCategory cate = loanCategoryProvider.findById(id);
            if(cate != null){
                return cate.getCategory_name();
            }
        }
        return null;
    }
}
